package com.seteam.collabcrossword;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;

import com.seteam.collabcrossword.messages.client.Connect;
import com.seteam.collabcrossword.messages.client.GetBoard;
import com.seteam.collabcrossword.messages.server.Connected;

public class TestClient {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Socket echoSocket = null;
		ObjectOutputStream outObject = null;
		ObjectInputStream inObject = null;

		try {
			echoSocket = new Socket("localhost", 5000);

			// Sending the message to the server to connect, Includes the client
			// IP address
			InetAddress ip = InetAddress.getLocalHost();
			Connect connet = new Connect(ip);
			
			//write the object to the server socket.
			outObject = new ObjectOutputStream(
					echoSocket.getOutputStream());
			outObject.writeObject(connet);

			//read the data from the server socket, reply from the server
			inObject = new ObjectInputStream(echoSocket.getInputStream());
			Connected connected = (Connected)inObject.readObject();
			
			
			
			
			
			outObject.close();
			echoSocket.close();
			
		} catch (UnknownHostException e) {
			System.err.println("Don't know about host: localhost.");
			System.exit(1);
		} catch (IOException e) {
			System.err.println("Couldn't get I/O for "
					+ "the connection to: localhost.");
			System.exit(1);
		}catch (ClassNotFoundException e) {
			// TODO: handle exception
			e.printStackTrace();
		}
		
	}

}
